#include "behavior_tree_retry_policy.h"
#include <behaviortree_cpp_v3/decorators/retry_node.h>

namespace policy
{
BehaviorTreeRetryPolicy::BehaviorTreeRetryPolicy(const std::string &name, int retry_count)
    : BehaviorTreePolicy(name)
{
    policy_tree_node_ = std::make_unique<BT::RetryNode>(name + "_retry_node", retry_count);
}
void BehaviorTreeRetryPolicy::setRetryCount(int32_t count)
{
    auto *node = dynamic_cast<BT::RetryNode *>(policy_tree_node_.get());
    if (nullptr == node)
    {
        throw std::runtime_error("behavior tree retry policy case fail");
    }
    node->setRetryCount(count);
}
int32_t BehaviorTreeRetryPolicy::getRetryCount() const
{
    auto *node = dynamic_cast<BT::RetryNode *>(policy_tree_node_.get());
    if (nullptr == node)
    {
        throw std::runtime_error("behavior tree retry policy case fail");
    }
    return node->getRetryCount();
}
BehaviorTreeRetryPolicy::~BehaviorTreeRetryPolicy() = default;

}
